macos: fix coordinates and state when querying device
authorChristian Hergert <chergert@redhat.com>
Wed, 14 Oct 2020 18:32:20 +0000 (11:32 -0700)
committerChristian Hergert <chergert@redhat.com>
Wed, 14 Oct 2020 18:34:44 +0000 (11:34 -0700)
When querying a device, we need to ensure we are providing coordinates
in the coordinate system of the surface. Further, we need to actually
provide the button and keyboard state.

This fixes some issues related to dragging scrollbars and selecting list
box rows more reliably.

gdk/macos/gdkmacossurface.c

index 8139d2c84d8e25400355678150380d45e4c178c4..4b8fedcaf4e963be0f41e2701578d5a097b474bc 100644 (file)
@@ -238,8 +238,6 @@ gdk_macos_surface_get_device_state (GdkSurface      *surface,
   GdkDisplay *display;
   NSWindow *nswindow;
   NSPoint point;
-  int x_tmp;
-  int y_tmp;
 
   g_assert (GDK_IS_MACOS_SURFACE (surface));
   g_assert (GDK_IS_MACOS_DEVICE (device));
@@ -247,18 +245,20 @@ gdk_macos_surface_get_device_state (GdkSurface      *surface,
   g_assert (y != NULL);
   g_assert (mask != NULL);
 
+  if (GDK_SURFACE_DESTROYED (surface))
+    return FALSE;
+
   display = gdk_surface_get_display (surface);
   nswindow = _gdk_macos_surface_get_native (GDK_MACOS_SURFACE (surface));
   point = [nswindow mouseLocationOutsideOfEventStream];
 
-  _gdk_macos_display_from_display_coords (GDK_MACOS_DISPLAY (display),
-                                          point.x, point.y,
-                                          &x_tmp, &y_tmp);
+  *mask = _gdk_macos_display_get_current_keyboard_modifiers (GDK_MACOS_DISPLAY (display))
+        | _gdk_macos_display_get_current_mouse_modifiers (GDK_MACOS_DISPLAY (display));
 
-  *x = x_tmp;
-  *y = x_tmp;
+  *x = point.x;
+  *y = point.y - surface->height;
 
-  return TRUE;
+  return *x >= 0 && *y >= 0 && *x < surface->width && *y < surface->height;
 }
 
 static void